package com.koron.order.concession.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.order.concession.bean.po.ConcessionInfluencePo;
import com.koron.order.concession.mapper.ConcessionInfluenceMapper;
import com.koron.order.concession.service.ConcessionInfluenceService;
import org.apache.commons.collections4.CollectionUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 让步接收单-影响对应从表(ConcessionInfluence)表服务实现类
 *
 * @author zhouj
 * @since 2022-01-14 10:14:07
 */
@Service("concessionInfluenceService")
public class ConcessionInfluenceServiceImpl implements ConcessionInfluenceService {

    @Override
    @TaskAnnotation("insertOrUpdate")
    public int insertOrUpdate(SessionFactory factory, ConcessionInfluencePo concessionInfluence) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.insertOrUpdate(concessionInfluence);
    }

    @Override
    @TaskAnnotation("insertOrUpdateBatch")
    public int insertOrUpdateBatch(SessionFactory factory, List<ConcessionInfluencePo> concessionInfluenceList) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.insertOrUpdateBatch(concessionInfluenceList);
    }

    @Override
    @TaskAnnotation("insert")
    public int insert(SessionFactory factory, ConcessionInfluencePo concessionInfluence) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.insert(concessionInfluence);
    }

    @Override
    @TaskAnnotation("insertBatch")
    public int insertBatch(SessionFactory factory, List<ConcessionInfluencePo> concessionInfluenceList) {

        if (CollectionUtils.isEmpty(concessionInfluenceList)) {
            return 0;
        }

        //先根据concessionId 删除

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.insertBatch(concessionInfluenceList);
    }

    @Override
    @TaskAnnotation("update")
    public int update(SessionFactory factory, ConcessionInfluencePo concessionInfluence) {
        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);
        return mapper.update(concessionInfluence);
    }

    @Override
    @TaskAnnotation("deleteById")
    public int deleteById(SessionFactory factory, String id) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);
        return mapper.deleteById(id);
    }

    @Override
    @TaskAnnotation("deleteByConcessionId")
    public int deleteByConcessionId(SessionFactory factory, String concessionId) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);
        return mapper.deleteByConcessionId(concessionId);
    }

    @Override
    @TaskAnnotation("queryById")
    public ConcessionInfluencePo queryById(SessionFactory factory, String id) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.queryById(id);
    }

    @Override
    @TaskAnnotation("queryList")
    public List<ConcessionInfluencePo> queryList(SessionFactory factory, ConcessionInfluencePo concessionInfluence) {

        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        return mapper.queryList(concessionInfluence);
    }

    @Override
    @TaskAnnotation("queryPageList")
    public PageInfo queryPageList(SessionFactory factory, ConcessionInfluencePo concessionInfluence, PageQuery pageQuery) {

        PageHelper.startPage(pageQuery.getPage(), pageQuery.getPageSize(), pageQuery.getOrderBy());
        ConcessionInfluenceMapper mapper = factory.getMapper(ConcessionInfluenceMapper.class);

        List<ConcessionInfluencePo> list = mapper.queryList(concessionInfluence);

        return new PageInfo(list);
    }

}
